﻿namespace FiftyOne.Foundation.Mobile.Detection.Wurfl.Handlers
{
    using FiftyOne.Foundation.Mobile.Detection.Wurfl.Matchers;
    using FiftyOne.Foundation.Mobile.Detection.Wurfl.Matchers.Version;
    using System;
    using System.Text.RegularExpressions;

    internal abstract class VersionHandler : EditDistanceHandler
    {
        private Regex[] _versionRegexes;
        private const int CONFIDENCE = 9;

        internal VersionHandler(string[] patterns)
        {
            this._versionRegexes = null;
            this._versionRegexes = new Regex[patterns.Length];
            for (int i = 0; i < this._versionRegexes.Length; i++)
            {
                this._versionRegexes[i] = new Regex(patterns[i], RegexOptions.Compiled);
            }
        }

        internal VersionHandler(string pattern)
        {
            this._versionRegexes = null;
            this._versionRegexes = new Regex[] { new Regex(pattern, RegexOptions.Compiled) };
        }

        protected internal override Results Match(string userAgent)
        {
            Results results = FiftyOne.Foundation.Mobile.Detection.Wurfl.Matchers.Version.Matcher.Match(userAgent, this);
            if (results == null)
            {
                return base.Match(userAgent);
            }
            return results;
        }

        internal override byte Confidence
        {
            get
            {
                return 9;
            }
        }

        internal Regex[] VersionRegexes
        {
            get
            {
                return this._versionRegexes;
            }
        }
    }
}

